/*
Navicat SQL Server Data Transfer

Source Server         : LOCALHOST
Source Server Version : 110000
Source Host           : .:1433
Source Database       : AAACHAM2
Source Schema         : dbo

Target Server Type    : SQL Server
Target Server Version : 110000
File Encoding         : 65001

Date: 2014-04-25 13:29:02
*/


-- ----------------------------
-- Table structure for tb0105
-- ----------------------------
DROP TABLE [dbo].[tb0105]
GO
CREATE TABLE [dbo].[tb0105] (
[TransactionID] varchar(20) NOT NULL ,
[VoucherID] varchar(20) NOT NULL ,
[BatchID] varchar(20) NULL ,
[InventoryID] varchar(20) NOT NULL ,
[UnitID] varchar(20) NULL ,
[ActualQuantity] money NULL ,
[UnitPrice] money NULL ,
[OriginalAmount] money NULL ,
[ConvertedAmount] money NULL ,
[Notes] nvarchar(500) NULL ,
[TranMonth] int NULL ,
[TranYear] int NULL ,
[DivisionID] varchar(20) NULL ,
[CurrencyID] varchar(20) NULL DEFAULT ('VND') ,
[ExchangeRate] money NULL DEFAULT ((1)) ,
[SaleUnitPrice] money NULL ,
[SaleAmount] money NULL ,
[DiscountAmount] money NULL ,
[SourceNo] varchar(30) NULL ,
[DebitAccountID] varchar(20) NULL ,
[CreditAccountID] varchar(20) NULL ,
[LocationID] varchar(20) NULL ,
[ImLocationID] varchar(50) NULL ,
[LimitDate] datetime NULL ,
[Orders] int NOT NULL DEFAULT ((0)) ,
[ConversionFactor] money NULL ,
[ReTransactionID] varchar(20) NULL ,
[ReVoucherID] varchar(20) NULL ,
[Ana01ID] varchar(20) NULL ,
[Ana02ID] varchar(20) NULL ,
[Ana03ID] varchar(20) NULL ,
[PeriodID] varchar(20) NULL ,
[ProductID] varchar(20) NULL ,
[OrderID] varchar(20) NULL ,
[InventoryName1] nvarchar(150) NULL ,
[Ana04ID] varchar(20) NULL ,
[Ana05ID] varchar(20) NULL 
)


GO

-- ----------------------------
-- Indexes structure for table tb0105
-- ----------------------------

-- ----------------------------
-- Primary Key structure for table tb0105
-- ----------------------------
ALTER TABLE [dbo].[tb0105] ADD PRIMARY KEY NONCLUSTERED ([TransactionID])
GO

-- ----------------------------
-- Checks structure for table tb0105
-- ----------------------------
ALTER TABLE [dbo].[tb0105] ADD CHECK (([VoucherID] IS NOT NULL AND [VoucherID]<>''))
GO

-- ----------------------------
-- Triggers structure for table tb0105
-- ----------------------------
--DROP TRIGGER [dbo].[AX2007]
GO
CREATE TRIGGER [dbo].[AX2007]
ON [dbo].[tb0105]
AFTER DELETE
AS

Declare		@D07_Cursor		Cursor,
		@BaseCurrencyID as varchar(20)
Declare  	
	@KindVoucherID  	TinyInt ,
	@TransactionID		Varchar(20),
	@DivisionID		Varchar(20),		
	@RDVoucherID		Varchar(20), 	
	@InventoryID		Varchar(20), 	
	@MethodID		tinyint,
	@TranYear		Int,		
	@TranMonth		int,
	@ActualQuantity	Decimal(28,8),	
	@ConvertedQuantity	Decimal(28,8),	
	@ConvertedUnitPrice	Decimal(28,8),	
	@ConvertedAmount	Money,		
	@OriginalAmount	Money,
	@DebitAccountID	Varchar(20), 	
	@CreditAccountID	Varchar(20),
	@WareHouseID		Varchar(20),	
	@WareHouseID2	Varchar(20),
	@IsLimitDate 		tinyint,
	@IsSource		tinyint,
	@TableID		varchar(20)
	
Set @D07_Cursor = Cursor Scroll KeySet For
Select 		Del.TransactionID, Del.DivisionID, Del.VoucherID, Del.TranYear, Del.TranMonth,   ---- Thong tin chung				
		T09.WareHouseID, T09.WareHouseID2,    KindVoucherID,	
		Del.InventoryID, 
		T02.MethodID,
		ActualQuantity, 
		ActualQuantity*isnull(T04.ConversionFactor,1),				
		OriginalAmount, ConvertedAmount,
		DebitAccountID,CreditAccountID,
		T02.IsLimitDate,
		T02.IsSource,
		T09.TableID
From 	Deleted Del 	Inner Join tb0104 T09 	On 	Del.VoucherID = T09.VoucherID And 
							Del.DivisionID = T09.DivisionID And
							Del.TranMonth = T09.TranMonth And 
							Del.TranYear = T09.TranYear
			inner join tb0054 T02 	on 	Del.InventoryID = T02.InventoryID 
			Left  join tb0061 T04 	On	Del.UnitID 	= T04.UnitID and
							Del.InventoryID 	= T04.InventoryID

Open @D07_Cursor
Fetch Next From @D07_Cursor Into @TransactionID, @DivisionID, @RDVoucherID, @TranYear, @TranMonth,   ---- Thong tin chung		
		@WareHouseID, @WareHouseID2,   @KindVoucherID,		 	
		@InventoryID,   @MethodID, 	@ActualQuantity, 
		@ConvertedQuantity, @OriginalAmount, @ConvertedAmount,
		@DebitAccountID,@CreditAccountID,
		@IsLimitDate, @IsSource, @TableID                                       

While @@FETCH_STATUS = 0
Begin	
		
		----- Xoa bang tinh gia	
		If @KindVoucherID in (1,3,5,7,9)
			if @IsSource =1 or @IsLimitDate =1 or @MethodID in (1,2,3)
				Delete tb0007 Where 	DivisionID =@DivisionID and
							WareHouseID =@WareHouseID and
							ReVoucherID =@RDVoucherID and
							ReTransactionID = @TransactionID
				

		If @KindVoucherID<>3 and ( @TableID in ('tb0104','tb3010') )
			Delete tb0191
				Where TransactionID = @TransactionID and
					VoucherID = @RDVoucherID and
					TableID = @TableID and
					TranMOnth =@TranMOnth and
					TranYear =@TranYear

		if @KindVoucherID =3 and (@DebitAccountID <> @CreditAccountID)
			Delete tb0191
				Where TransactionID = @TransactionID and
					VoucherID = @RDVoucherID and
					TableID = @TableID and
					TranMOnth =@TranMOnth and
					TranYear =@TranYear
											

	If @KindVoucherID = 3 
		Begin
			Exec pr0054 @DivisionID, @WareHouseID, @TranMonth, @TranYear, @InventoryID, @ConvertedAmount, @ConvertedQuantity, @DebitAccountID, @CreditAccountID, 11 -- (1) la cap nhat tang,(0 ) la cap nhat giam
			Exec pr0054 @DivisionID, @WareHouseID2, @TranMonth, @TranYear, @InventoryID, @ConvertedAmount, @ConvertedQuantity, @DebitAccountID, @CreditAccountID, 10 -- (1) la cap nhat tang,(0 ) la cap nhat giam
		End 
	Else
		
		 if @KindVoucherID in (1,5,7,9)		----- truong hop Xoa phieu nhap
			Exec pr0054 @DivisionID, @WareHouseID, @TranMonth, @TranYear, @InventoryID, @ConvertedAmount, @ConvertedQuantity,  @DebitAccountID, @CreditAccountID,  1 -- (1) la cap nhat tang,(0 ) la cap nhat giam
		    Else if @KindVoucherID in (2,4,6,8)	----- Truong hop Xoa phieu xuat
			Exec pr0054 @DivisionID, @WareHouseID, @TranMonth, @TranYear, @InventoryID, @ConvertedAmount, @ConvertedQuantity,  @DebitAccountID, @CreditAccountID,  0 -- (1) la cap nhat tang,(0 ) la cap nhat giam
		

	Fetch Next From @D07_Cursor Into @TransactionID, @DivisionID, @RDVoucherID, @TranYear, @TranMonth,   ---- Thong tin chung		
			@WareHouseID, @WareHouseID2,   @KindVoucherID,		 	
			@InventoryID,   @MethodID, 	@ActualQuantity, 
			@ConvertedQuantity, @OriginalAmount, @ConvertedAmount,
			@DebitAccountID,@CreditAccountID,
			@IsLimitDate, @IsSource, @TableID                                       
End
Close @D07_Cursor
DeAllocate @D07_Cursor







GO
--DROP TRIGGER [dbo].[AY2007]
GO
CREATE TRIGGER [dbo].[AY2007]
ON [dbo].[tb0105]
AFTER INSERT
AS
Declare		@D07_Cursor		Cursor,
		@BaseCurrencyID as varchar(20)

Declare  	
	@KindVoucherID  	TinyInt ,
	@TransactionID		Varchar(20),
	@DivisionID		Varchar(20),	@ModuleID		Varchar(20),
	@VoucherTypeID	Varchar(20),			
	@RDVoucherID		Varchar(20), 	@RDVoucherNo	Varchar(20),	
	@BatchID		Varchar(20),
	@RDVoucherDate	Datetime,			
	@TranYear		Int,		@TranMonth		int,
	@InventoryID		Varchar(20),	@UnitID		Varchar(10),
	@ActualQuantity	Decimal(28,8),	@UnitPrice		Decimal(28,8),
	@ConvertedQuantity	Decimal(28,8),	@ConvertedUnitPrice	Decimal(28,8),
	@CurrencyID		Varchar(20),	@ExchangeRate	Money,		
	@ConvertedAmount	Money,		@OriginalAmount	Money,
	@DebitAccountID	Varchar(20), 	@CreditAccountID	Varchar(20),
	@WareHouseID		Varchar(20),	@WareHouseID2	Varchar(20),
	@Description		Varchar(255),	@SourceNo		Varchar(20),
	@CreateUserID		Varchar(20),	@CreateDate		Datetime,
	@EmployeeID		Varchar(20),	@MethodID		tinyint,
	@ObjectID		Varchar(20),
	@Status		tinyint,
	@IsLimitDate 		tinyint,
	@IsSource		tinyint,		
	@LimitDate		Datetime,
	@TableID 		Varchar(20),
	@Ana01ID		Varchar(20),
	@Ana02ID		Varchar(20),
	@Ana03ID		Varchar(20),
	@Notes			Varchar(250),
	@PeriodID		varchar(20),
	@ProductID		varchar(20),
	@OrderID		varchar(20),
	@IsTemp		tinyint




Set @D07_Cursor = Cursor Scroll KeySet For
Select 		Ins.TransactionID, ins.DivisionID, ins.VoucherID, ins.TranYear, ins.TranMonth,   ---- Thong tin chung
		T09.VoucherDate,  T09.VoucherNo, 
		EmployeeID,  ObjectID,   T09.CreateUserID, T09.CreateDate,  Description,		
		T09.WareHouseID, T09.WareHouseID2,  0 , KindVoucherID,
		ins.CurrencyID, ins.ExchangeRate,
		ins.InventoryID, ins.UnitID,  T02.MethodID as MethodID , 
		ActualQuantity, UnitPrice,

		---ActualQuantity*isnull(T04.ConversionFactor,1),		
		isnull(ActualQuantity,0), 
		UnitPrice/isnull(T04.ConversionFactor,1),
		OriginalAmount, ConvertedAmount,
		DebitAccountID,CreditAccountID,    ins.SourceNo,
		T02.IsLimitDate, T02.IsSource, Ins.LimitDate,
		T09.TableID,
		T09.BatchID,
		Ana01ID, Ana02ID, Ana03ID, ins.Notes,
		VoucherTypeID,
		Ins.PeriodID, Ins.ProductID,
		W.IsTemp,
		Ins.OrderID				

From 	inserted ins 	Inner Join tb0104 T09 	On 	ins.VoucherID = T09.VoucherID And 
							ins.DivisionID = T09.DivisionID And
							ins.TranMonth = T09.TranMonth And 
							ins.TranYear = T09.TranYear
			inner join tb0054 T02 	on 	ins.InventoryID = T02.InventoryID 
			Left  join tb0061 T04 	On	ins.UnitID 	= T04.UnitID and
							ins.InventoryID 	= T04.InventoryID
			Left join tb0055  W	on 	W.WareHouseID = T09.WareHouseID


Open @D07_Cursor
Fetch Next From @D07_Cursor Into @TransactionID, @DivisionID, @RDVoucherID, @TranYear, @TranMonth,   ---- Thong tin chung
		@RDVoucherDate,  @RDVoucherNo, 
		@EmployeeID,  @ObjectID,   @CreateUserID, @CreateDate,  @Description,
		@WareHouseID, @WareHouseID2,  @Status, @KindVoucherID,
		@CurrencyID, @ExchangeRate,	
		@InventoryID, @UnitID,  @MethodID, 
		@ActualQuantity, @UnitPrice,
		@ConvertedQuantity, @ConvertedUnitPrice,	@OriginalAmount, @ConvertedAmount,
		@DebitAccountID,@CreditAccountID,    @SourceNo,
		@IsLimitDate, @IsSource, @LimitDate, @TableID, @BatchID,
		@Ana01ID, @Ana02ID, @Ana03ID, @Notes,
		@VoucherTypeID, @PeriodID, @ProductID, @IsTemp, @OrderID				
                                         

While @@FETCH_STATUS = 0
Begin	

	Exec 	pr0060  @TransactionID, @DivisionID, @RDVoucherID, @TranYear, @TranMonth,   
		@RDVoucherDate,  @RDVoucherNo, 
		@EmployeeID,  @ObjectID,  @CreateUserID, @CreateDate,  @Description,
		@WareHouseID, @WareHouseID2,  @Status, @KindVoucherID,
		@CurrencyID, @ExchangeRate,	@InventoryID, @UnitID,  @MethodID, @ActualQuantity, @UnitPrice,
		@ConvertedQuantity,@ConvertedUnitPrice,	@OriginalAmount, @ConvertedAmount,
		@DebitAccountID,@CreditAccountID,    @SourceNo,
		@IsLimitDate, @IsSource, @LimitDate ,@TableID,@BatchID,@Ana01ID, @Ana02ID, @Ana03ID, @Notes,@VoucherTypeID, @PeriodID, @ProductID, @IsTemp, @OrderID	


Fetch Next From @D07_Cursor Into @TransactionID, @DivisionID, @RDVoucherID, @TranYear, @TranMonth,   ---- Thong tin chung
		@RDVoucherDate,  @RDVoucherNo, 
		@EmployeeID,  @ObjectID,   @CreateUserID, @CreateDate,  @Description,
		@WareHouseID, @WareHouseID2,  @Status, @KindVoucherID,
		@CurrencyID, @ExchangeRate,	
		@InventoryID, @UnitID,  @MethodID, 
		@ActualQuantity, @UnitPrice,
		@ConvertedQuantity, @ConvertedUnitPrice,	@OriginalAmount, @ConvertedAmount,
		@DebitAccountID,@CreditAccountID,    @SourceNo,
		@IsLimitDate, @IsSource, @LimitDate, @TableID,
		@BatchID,@Ana01ID, @Ana02ID, @Ana03ID, @Notes,
		@VoucherTypeID,@PeriodID, @ProductID, @IsTemp, @OrderID					
                                       

End
Close @D07_Cursor
DeAllocate @D07_Cursor




GO
--DROP TRIGGER [dbo].[AZ2007]
GO
CREATE TRIGGER [dbo].[AZ2007]
ON [dbo].[tb0105]
AFTER UPDATE
AS
Declare		@D07_Cursor		Cursor,
		@BaseCurrencyID as varchar(20)

Declare  	
	@KindVoucherID  	TinyInt ,
	@TransactionID		Varchar(20),
	@DivisionID		Varchar(20),	@ModuleID		Varchar(20),
	@VoucherTypeID	Varchar(20),			
	@RDVoucherID		Varchar(20), 	@RDVoucherNo	Varchar(20),	
	@BatchID 		Varchar(20),
	@RDVoucherDate	Datetime,			
	@TranYear		Int,		@TranMonth		int,
	@InventoryID		Varchar(20),	@UnitID		Varchar(10),
	@UnitPrice		Decimal(28,8),
	@CurrencyID		Varchar(20),	@ExchangeRate	Money,		
	@ConvertedAmount	Money,		@OriginalAmount	Money,
	@DebitAccountID	Varchar(20), 	@CreditAccountID	Varchar(20),
	@DebitAccountID_Old	Varchar(20), 	@CreditAccountID_Old	Varchar(20),
	@DebitAccountID_New	Varchar(20), 	@CreditAccountID_New	Varchar(20),
	@WareHouseID		Varchar(20),	@WareHouseID2	Varchar(20),
	@Description		Varchar(255),	@SourceNo		Varchar(20),
	@LimitDate		Datetime,						
	@EmployeeID		Varchar(20),	@MethodID		tinyint,
	@ObjectID		Varchar(20),	@IsLimitDate 		tinyint,
	@IsSource		tinyint,		@TableID		varchar(20),
	@Ana01ID		varchar(20), 	@Ana02ID		varchar(20), 	@Ana03ID		varchar(20),
	@Notes			varchar(250),	@PeriodID		varchar(20),	@ProductID 		varchar(20),  @OrderID as Varchar(20),
	@IsTemp		tinyint,
	@OldQuantity 		as Decimal(28,8),	@NewQuantity 		as Decimal(28,8),	@OldConvertedAmount as money,	@NewConvertedAmount as money,
	@LastModifyDate as datetime,	@LastModifyUserID as varchar(20),
	@OldProductID as varchar(20), @NewProductID as varchar(20),
	@OldPeriodID as varchar(20), @NewPeriodID as varchar(20)

Set @D07_Cursor = Cursor Scroll KeySet For
	Select  	ins.DivisionID, ins.TranMonth, Ins.TranYear, Ins.TransactionID, Ins.VoucherID, T6.BatchID, 
		T6.VoucherDate, T6.VoucherNo, T6.VoucherTypeID,
		T6.KindVoucherID, T6.TableID, T6.WareHouseID, T6.WareHouseID2,
		T6.ObjectID, T6.EmployeeID, T6.Description,
		T6.LastModifyDate, T6.LastModifyUserID,
		Ins.CurrencyID, Ins.ExchangeRate,
		Ins.InventoryID, Ins.UnitID, 
		T2.MethodID, T2.IsLimitDate, T2.IsSource,
		Ins.UnitPrice,
		Del.ActualQuantity,
		Ins.ActualQuantity,
		Del.ConvertedAmount,
		Ins.ConvertedAmount,
		ins.OriginalAmount,
		Del.DebitAccountID, Del.CreditAccountID,
		ins.DebitAccountID, Ins.CreditAccountID,
		Ins.Ana01ID, Ins.Ana02ID, Ins.Ana03ID, Ins.Notes, 
		ins.PeriodID,
		Ins.ProductID, 
		Del.PeriodID,
		Del.ProductID,
		Ins.LimitDate,  ins.SourceNo, ins.OrderID
	From Deleted Del	 inner join Inserted Ins on Ins.TransactionID = Del.TransactionID 
				 inner join tb0104 T6 on T6.VoucherID = ins.VoucherID
				 inner join tb0054 T2 on T2.InventoryID = ins.InventoryID
 Open @D07_Cursor
Fetch Next From @D07_Cursor Into @DivisionID, @TranMonth, @TranYear, @TransactionID, @RDVoucherID, @BatchID,
				@RDVoucherDate, @RDVoucherNo, @VoucherTypeID,
				@KindVoucherID, @TableID, @WareHouseID, @WareHouseID2,   
				@ObjectID,@EmployeeID, @Description,
				@LastModifyDate, @LastModifyUserID, 
				@CurrencyID, @ExchangeRate,	
				@InventoryID, @UnitID,
				@MethodID,@IsLimitDate, @IsSource,
				@UnitPrice,
				@OldQuantity, @NewQuantity,	 
				@OldConvertedAmount, @NewConvertedAmount,
				@OriginalAmount,
				@DebitAccountID_Old, @CreditAccountID_Old,
				@DebitAccountID_New , @CreditAccountID_New,
				@Ana01ID, @Ana02ID, @Ana03ID, @Notes, 
				@NewPeriodID,  @NewProductID, 
				@OldPeriodID,  @OldProductID, 
				@LimitDate,  @SourceNo, @OrderID

While @@FETCH_STATUS = 0
Begin	
	--print ' Old: '+str(@OldConvertedAmount) +'  New: '+str(@NewConvertedAmount)

	If @KindVoucherID in (1,3,5,7,9)  --- Truong hop phieu nhap kho
			if @IsSource =1 Or @IsLimitDate =1 or @MethodID in (1,2,3)
				Update tb0007 		Set 	ReQuantity = @NewQuantity,
								EndQuantity = @NewQuantity - isnull(DeQuantity,0),
								UnitPrice = @UnitPrice,
								ReVoucherDate = @RDVoucherDate
							Where 	DivisionID =@DivisionID and
							WareHouseID =@WareHouseID and

							ReVoucherID =@RDVoucherID and
							ReTransactionID = @TransactionID

		EXEC  	pr0061 	@KindVoucherID, @DivisionID, @TranMonth, @TranYear,@WareHouseID, @WareHouseID2, @InventoryID,
					@DebitAccountID_Old , @CreditAccountID_Old , @DebitAccountID_New , @CreditAccountID_New , 
					@OldQuantity , @NewQuantity , @OldConvertedAmount , @NewConvertedAmount



			If ( @TableID in ('tb0104','tb3010'))  and @KindVoucherID<>3 
			Update tb0191 Set  	VoucherDate = @RDVoucherDate, VoucherNo = @RDVoucherNo, VoucherTypeID = @VoucherTypeID,
						ObjectID = @ObjectID, VDescription  = @Description, BDescription = @Description,
						LastModifyDate = @LastModifyDate, LastModifyUserID = @LastModifyUserID, 
						CurrencyID = @CurrencyID, ExchangeRate = @ExchangeRate,	
						InventoryID = @InventoryID, UnitID = @UnitID, UnitPrice =@UnitPrice,
						Quantity = @NewQuantity, ConvertedAmount = @NewConvertedAmount , OriginalAmount =@OriginalAmount,
						OriginalAmountCN =@OriginalAmount, CurrencyIDCN = @CurrencyID, ExchangeRateCN = @ExchangeRate,
						DebitAccountID =@DebitAccountID_New, CreditAccountID = @CreditAccountID_New,
						Ana01ID = @Ana01ID, Ana02ID = @Ana02ID, Ana03ID = @Ana03ID, 
						TDescription = @Notes, 
						OrderID = @OrderID,
						PeriodID = (Case when isnull(@OldPeriodID,'') = isnull(@NewPeriodID,'') then PeriodID else @NewPeriodID end),  
						ProductID = (Case when isnull(@OldProductID,'') = isnull(@NewProductID,'') then ProductID else @NewProductID end)  

				Where 	TransactionID =@TransactionID and
					VoucherID =@RDVoucherID and
					TableID = @TableID and
					TranMonth = @TranMonth and
					TranYear =@TranYear 
			Else
				If @KindVoucherID =3  
					Begin
						---1. Delete tb0191 (neu co du lieu)						
						Delete tb0191	Where TransactionID = @TransactionID and	VoucherID = @RDVoucherID and TableID = @TableID and TranMOnth =@TranMOnth and TranYear =@TranYear

						---2. Insert du lieu neu thoa man dieu kien
					If @DebitAccountID_New <> @CreditAccountID_New
					Insert tb0191	(VoucherID,  BatchID,     TransactionID,        TableID,
				            			 DivisionID,   TranMonth,   TranYear,    TransactionTypeID,
						 	CurrencyID,          CurrencyIDCN, ObjectID,   DebitAccountID,   CreditAccountID, 
							 ExchangeRate,          OriginalAmount,                 ConvertedAmount,
							 ExchangeRateCN,          OriginalAmountCN,                 
				             			 VoucherDate,              VoucherTypeID,                               VoucherNo            ,                        
							 Orders ,EmployeeID ,   Ana01ID, Ana02ID, Ana03ID,
				             			 VDescription ,  BDescription , TDescription,    Quantity,   UnitPrice,
							InventoryID,          UnitID,               Status,        
							ProductID, PeriodID,  OrderID,
							 CreateDate ,                 CreateUserID ,        LastModifyDate  ,            LastModifyUserID )    
					Values
							(@RDVoucherID, isnull(@BatchID,''), @TransactionID, @TableID ,
							@DivisionID, @TranMonth, @TranYear, 
							Case When @KindVoucherID in (1,3,5,7) then 'T05' else
							Case When @KindVoucherID in ( 2,4,6) then 'T06' else'T99' end End,
							@CurrencyID,        @CurrencyID, @ObjectID,   @DebitAccountID_New, @CreditAccountID_New,
							@ExchangeRate,          @OriginalAmount,                @NewConvertedAmount,
							@ExchangeRate,          @OriginalAmount,
					             		 @RDVoucherDate,              @VoucherTypeID,                               @RDVoucherNo            ,                        
							 1 , @EmployeeID , @Ana01ID, @Ana02ID, @Ana03ID,        
						               @Description ,  @Description , @Notes ,   @NewQuantity,      @UnitPrice ,                
							 @InventoryID,          @UnitID,      0,
							 @ProductID, @PeriodID, @OrderID,
							 @LastModifyDate,                  @LastModifyUserID,         @LastModifyDate,              @LastModifyUserID )





					End


			

	Fetch Next From @D07_Cursor Into @DivisionID, @TranMonth, @TranYear, @TransactionID, @RDVoucherID, @BatchID,
				@RDVoucherDate, @RDVoucherNo, @VoucherTypeID,
				@KindVoucherID, @TableID, @WareHouseID, @WareHouseID2,   
				@ObjectID,@EmployeeID, @Description,
				@LastModifyDate, @LastModifyUserID, 
				@CurrencyID, @ExchangeRate,	
				@InventoryID, @UnitID,
				@MethodID,@IsLimitDate, @IsSource,
				@UnitPrice,
				@OldQuantity, @NewQuantity,	 
				@OldConvertedAmount, @NewConvertedAmount,
				@OriginalAmount,
				@DebitAccountID_Old, @CreditAccountID_Old,
				@DebitAccountID_New, @CreditAccountID_New,
				@Ana01ID, @Ana02ID, @Ana03ID, @Notes, 
				@NewPeriodID,  @NewProductID, 
				@OldPeriodID,  @OldProductID, 
				@LimitDate,  @SourceNo, @OrderID
End
Close @D07_Cursor







GO
